package com.yanqu.road.server.cmd.activity.douluoshrek;

import com.yanqu.road.pb.activity.DouLuoShrekProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.shrek.DouLuoShrekModule;
import com.yanqu.road.server.manger.activity.shrek.DouLuoShrekMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_DOULUOSHREK_DELA_EVENT, desc = "")
public class ShrekDealEventCmd extends AbstractCommand {


    private int activityId;
    private int buildingId;
    private int eventId;
    private int choice;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DouLuoShrekProto.DealEventReqMsg reqMsg = DouLuoShrekProto.DealEventReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        buildingId = reqMsg.getBuildingId();
        eventId = reqMsg.getEventId();
        choice = reqMsg.getChoice();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(!DouLuoShrekMgr.activityInTime() || activityId != DouLuoShrekMgr.getActivityTimeAcId()){
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
        DouLuoShrekProto.DealEventRespMsg.Builder respMsg = player.getModule(DouLuoShrekModule.class).dealEvent(buildingId,eventId,choice);
        player.sendPacket(Protocol.U_DOULUOSHREK_DELA_EVENT, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            DouLuoShrekProto.EnterShrekBossRespMsg.Builder respMsg = DouLuoShrekProto.EnterShrekBossRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_DOULUOSHREK_DELA_EVENT, respMsg);
        }
    }
}
